package com.wjx;

import org.junit.Test;

import java.io.FileOutputStream;
import java.io.ObjectOutputStream;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

public class Consumer {


    @Test
    public void request(){
        UserService userService = (UserService)Proxy.newProxyInstance(this.getClass().getClassLoader(), new Class[]{UserService.class}, new InvocationHandler() {
            @Override
            public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
                ObjectOutputStream objectOutputStream = new ObjectOutputStream(new FileOutputStream("D:\\王建新\\Desktop\\request.data"));
                objectOutputStream.writeUTF(UserService.class.getName());
                objectOutputStream.writeUTF(method.getName());
                objectOutputStream.writeObject(method.getParameterTypes());
                for (Object arg : args) {
                    objectOutputStream.writeObject(arg);
                }
                objectOutputStream.flush();
                objectOutputStream.close();
                return null;
            }
        });
        userService.getUserById(1L);
    }
}
